<?php

namespace App\Http\Controllers\YApi;

// use Illuminate\Http\Request;
use Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Session;
use Redirect;
use Illuminate\Pagination\LengthAwarePaginator;

use App\Models\Book;
use App\Models\Shudan;
use App\Models\UsersReg;

class ShudanbookslistController extends Controller
{

  public function shudanbookslist($id)
    {
        $shudans = Shudan::find($id);   

        $shudanlist = $shudans->shudanlist;
        $arr = explode(',', $shudanlist); 
        //得到书单对应的书籍信息
        for($i=0; $i < count($arr); $i++){
            $books[$i] = Book::find($arr[$i]);            
        }

        // $shudans['books'] = $books;
        $shudans['geshu'] = count($books);

        // 数组分页
        $currentPage = LengthAwarePaginator::resolveCurrentPage();
        $itemCollection = collect($books);
        $perPage = 10;
        $currentPageItems = $itemCollection->slice(($currentPage * $perPage) - $perPage, $perPage)->all();
        $paginatedItems = new LengthAwarePaginator($currentPageItems , count($itemCollection), $perPage);
        $paginatedItems->setPath(request::url());

        return $paginatedItems;
      
    }
    
}